package RPS::Import::Bandcamp::v26;

use strict;
use warnings;

use parent 'RPS::Import::Bandcamp::v25';


sub _fieldMapExtended {
    {
        mixed => {
            # version 26
            option1 => {
                countryCode     => 'AL',
                dateBegin       => 'A',
                dateEnd         => 'A',
                formatType      => 'AB',
                clientProductID => 'AF',
                artistName      => 'E',
                upc             => 'AG',
                albumName       => 'D',
                isrc            => 'AH',
                trackName       => 'D',
                units           => 'H',
                currencyCode    => 'F',
                retail          => 'G',
                totalRevenue    => 'AA',
                price           => 'AA',
                mediaType       => 'C',
            },
            # version 27
            option2 => {
                countryCode     => 'AJ',
                dateBegin       => 'A',
                dateEnd         => 'A',
                formatType      => 'Z',
                clientProductID => 'AD',
                artistName      => 'E',
                upc             => 'AE',
                albumName       => 'D',
                isrc            => 'AF',
                trackName       => 'D',
                units           => 'H',
                currencyCode    => 'F',
                retail          => 'G',
                totalRevenue    => 'Y',
                price           => 'Y',
                mediaType       => 'C',
            },
            # version 28
            option3 => {
                dateBegin       => 'A',
                dateEnd         => 'A',
                formatType      => 'Z',
                clientProductID => 'AB',
                artistName      => 'E',
                upc             => 'AC',
                albumName       => 'D',
                isrc            => 'AD',
                trackName       => 'D',
                units           => 'H',
                currencyCode    => 'F',
                retailPrice     => 'G',
                totalRevenue    => 'Y',
                price           => 'Y',
                mediaType       => 'C',
            },
            # version 29
            option4 => {
                dateBegin       => 'A',
                dateEnd         => 'A',
                formatType      => 'Z',
                clientProductID => 'AC',
                artistName      => 'E',
                upc             => 'AD',
                albumName       => 'D',
                isrc            => 'AE',
                trackName       => 'D',
                units           => 'H',
                currencyCode    => 'F',
                retailPrice     => 'G',
                totalRevenue    => 'Y',
                price           => 'Y',
                mediaType       => 'C',
            },
        },
    };
}

sub _unverifiedFieldMapExtended {
    {
        mixed => {
            # version 26
            option1 => {
                _productTypePhys => 'AB',
                _productTypeDig  => 'C',
                _netUnits        => 'H',
            },
            # version 27
            option2 => {
                _productTypePhys => 'Z',
                _productTypeDig  => 'C',
                _netUnits        => 'H',
            },
            # version 28
            option3 => {
                _productTypePhys => 'Z',
                _productTypeDig  => 'C',
                _netUnits        => 'H',
            },
            # version 29
            option4 => {
                _productTypePhys => 'Z',
                _productTypeDig  => 'C',
                _netUnits        => 'H',
            },
        }
    };
}

sub _headerIdentifierExtended {
    {
        mixed => {
            # version 26
            option1 => {
                upc => 'upc',
            },
            # version 27
            option2 => {
                upc => 'upc',
            },
            # version 28
            option3 => {
                upc => 'upc',
            },
            # version 29
            option4 => {
                upc => 'upc',
            },
        },
    };
}

sub countryCode {
    my $self = shift;

    return $self->version =~ /^(?:28|29)$/ ? 'US' : $self->SUPER::countryCode;
}

sub productType {
    my $self = shift;

    my $typeDig  = $self->_getByFieldName('_productTypeDig')  || '';
    my $typePhys = $self->_getByFieldName('_productTypePhys') || '';

    # exceptions (see RSD-1963 and RSD-2921)
    if ( $typeDig =~ /^refund$/i && $typePhys =~ /^digital (?:download|bundle)$/i ) {              # digital
        return RPS::File::Sale::TYPE_ALBUM;
    } elsif ( $typeDig =~ /^refund$/i && $typePhys =~ /(?:12'' Vinyl LP|12'' White Vinyl)/i ) {    # physical
        return RPS::File::Sale::TYPE_LP;
    } elsif ( $typeDig =~ /^refund$/i && $typePhys =~ /^.+$/ ) {
        return RPS::File::Sale::TYPE_CD;
    }

    # order is important
    if ( $typeDig =~ /^track$/i ) {                                                     # digital
        return RPS::File::Sale::TYPE_TRACK;
    } elsif ( $typeDig =~ /^album|refund|bundle$/i ) {
        return RPS::File::Sale::TYPE_ALBUM;
    } elsif ( $typeDig =~ /^reversal$/i ) {
        return $self->_getByFieldName('isrc')
            ? RPS::File::Sale::TYPE_TRACK
            : RPS::File::Sale::TYPE_ALBUM;
    } elsif ( $typePhys =~ /12''\sVinyl\sLP | \(?Vinyl\)? | \(?LP\)? $/xi ) {           # physical
        return RPS::File::Sale::TYPE_LP;
    } elsif ( $typePhys =~ /^Limited Edition Cassette$/i ) {
        return RPS::File::Sale::TYPE_CASS;
    }

    # all other cases except $typeDig = 'payout' see in _isValidSaleRecord
    return RPS::File::Sale::TYPE_CD;
}

1;
