package RPS::Import::Bandcamp::v30;

use strict;
use warnings;

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


sub _fieldMapExtended {
    {
        mixed => {
            option1 => {
                countryCode     => 'AX',
                dateBegin       => 'A',
                dateEnd         => 'A',
                formatType      => 'AB',
                clientProductID => 'AF',
                artistName      => 'E',
                upc             => 'AG',
                albumName       => 'D',
                isrc            => 'AH',
                trackName       => 'D',
                units           => 'H',
                currencyCode    => 'F',
                retailPrice     => 'G',
                totalRevenue    => 'AA',
                price           => 'AA',
                mediaType       => 'C',
            },
        },
    };
}

sub _unverifiedFieldMapExtended {
    {
        mixed => {
            option1 => {
                _productTypePhys => 'AB',
                _productTypeDig  => 'C',
                _netUnits        => 'H',
            }
        }
    };
}

sub _headerIdentifierExtended {
    {
        mixed => {
            option1 => {
                upc => 'upc',
            },
        },
    };
}

sub productType {
    my $self = shift;

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

    # order is important
    # digital
    if ( $typeDig =~ /^track$/i ) {
        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;
    }
    # physical
    elsif ( $typePhys =~ /^(?:Vinyl EP|.*\(?LP\)?)$/i ) {
        return RPS::File::Sale::TYPE_LP;
    }

    return RPS::File::Sale::TYPE_CD;
}

sub formatType {
    my $self = shift;

    my $type = $self->_getByFieldName('formatType') || '';
    if ( $type =~ /^(?:digital (?:download|bundle)|Happysad)$/i ) {
        return RPS::File::Sale::FORMAT_DOWNLOAD;
    }

    $self->fail( "Unable to determine format_type from: '$type'." );
}


1;