#!perl
use strict;
use warnings;
use Test::More qw(no_plan);
use lib 'lib';

BEGIN {
	use_ok( 'Audio::Tagger::Meta' );
}

require_ok("Audio::Tagger::Meta");

our $meta = Audio::Tagger::Meta->new;

isa_ok($meta,         "Audio::Tagger::Meta", "  new()" );

isa_ok($meta->artist, "Audio::Tagger::Meta::Artist");
isa_ok($meta->album,  "Audio::Tagger::Meta::Album");
isa_ok($meta->track,  "Audio::Tagger::Meta::Track");

my $artist = {
	name     => "The Crannberries",
	id       => "1",
	sortname => "Crannberies, The",};

my $artist2 = {
	name     => "Various Artists",
	id       => "3",
	sortname => "Various Artists",};

my $track = {
	name       => "Zombie",
	id         => "2",
	number     => 5,
	duration   => 3,
	score      => 50,};

my $album = {
	name   => "Best Hits Ever!",
	count  => 20,
	id     => 4,
	artist => $artist2,};


is_deeply($meta->artist($artist), $artist, "Checking artist deeply");
is_deeply($meta->track($track), $track, "Cheecking track deeply");
is_deeply($meta->album($album), $album, "Checking album deeply");

my $meta2 = Audio::Tagger::Meta->new($meta);

is_deeply($meta, $meta2);

$meta2 = Audio::Tagger::Meta->new;
$meta2->_meta($meta);

is_deeply($meta, $meta2);

$meta2 = Audio::Tagger::Meta->new({
	artist => $artist2,
	track  => $track,
	album  => $album,
	});

$meta->artist($artist2);

is_deeply($meta, $meta2);

$meta = bless {}, "Audio::Tagger::Meta";
isa_ok($meta->artist, "Audio::Tagger::Meta::Artist");
isa_ok($meta->album,  "Audio::Tagger::Meta::Album");
isa_ok($meta->track,  "Audio::Tagger::Meta::Track");

$meta = bless {}, "Audio::Tagger::Meta";
is_deeply($meta->artist($artist), $artist, "Checking artist deeply");
is_deeply($meta->track($track), $track, "Cheecking track deeply");
is_deeply($meta->album($album), $album, "Checking album deeply");


# Test that length, samplerate and bitrate complain loudly about being moved
my $t = Audio::Tagger::Meta::Track->new;

eval {$t->length;};
ok($@, "Check that length no longer works");

eval {$t->samplerate};
ok($@, "Check that samplerate no longer works");

eval {$t->bitrate};
ok($@, "Check that bitrate no longer works");

# Test that album->artist works in the way that is intended
my $a = Audio::Tagger::Meta::Album->new;
$a->artist;
$a->artist({});
$a->artist({
	id       => 'a',
	name     => 'b',
	sortname => 'c',
});
