#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2009 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------
package BookPub::Catalog::Import::Process::Fetcher::HachetteUK;
use strict;
use warnings;
use Data::Dumper;
use Net::FTP;

use lib '/app/tools/common/lib';
use lib '/app/tools/bookpub/lib';
use Common::RSApp;
use Common::Util;
use Common::Log;
use Common::Assert;
use Common::Process;
use Common::DB::Item::Language;
use BookPub::DB::Item::CatalogImport;
use BookPub::Config;

use BookPub::Catalog::Import::Process::Fetcher::FileHandler::CopyThenIgnore;
use BookPub::Catalog::Import::Process::Fetcher::Hachette::FileHandler::ImageArchive;
use BookPub::Catalog::Import::Process::Fetcher::Hachette::FileHandler::ONIXArchive;

use base 'BookPub::Catalog::Import::Process::Fetcher::Base';

sub _clientFTPDirectory {
    my ($self) = @_;
    return 'hachetteuk';
}

sub _sortTokenFromFilename {
    my ( $self, $filename ) = @_;

    # Overloading the base class to allow files named "covers.zip" to be
    # processed without a timestamp in the file name.
    #
    my $token;
    if ( $filename =~ /(\d{4,})/ ) {
        $token = $1;
    } elsif ($filename =~ /^covers\.zip$/i ) {
        # We sort the files by date so that we can process the oldest one first.
        # This is more relevant to the ONIX imports, which can include price
        # changes that need to happen in the right order.
        # For cover art (which is delivered weekly), we'll just hardcode the
        # date and try to process the file as soon as we can.
        $token = "20220829";
    }

    return $token;
}

###
1;    #
###
