import { ContractTemplateResolver } from './contract-template.resolver';
import { Booking } from '../modules/bookings/entities/booking.entity';
import { ServiceType } from '../modules/rule-engine/entities/service-type.entity';
import { CargoType } from '../modules/rule-engine/entities/cargo-type.entity';

describe('ContractTemplateResolver', () => {
  const resolver = new ContractTemplateResolver();

  function booking(partial: Partial<Booking>): Booking {
    return partial as Booking;
  }

  it('resolves import container ETB transport-only', () => {
    const key = resolver.resolve(
      booking({
        tradeDirection: 'IMPORT',
        freightType: 'CONTAINER',
        paymentCurrency: 'ETB',
        serviceType: { code: 'RAIL_ONLY', includesFirstMile: false, includesLastMile: false } as ServiceType,
      }),
    );
    expect(key).toBe('IMP_CON_ETB_TRANSPORT_ONLY');
  });

  it('resolves export bulk USD forwarding', () => {
    const key = resolver.resolve(
      booking({
        tradeDirection: 'EXPORT',
        freightType: 'BULK',
        paymentCurrency: 'USD',
        serviceType: {
          code: 'RAIL_FORWARDING',
          includesFirstMile: true,
          includesLastMile: false,
        } as ServiceType,
      }),
    );
    expect(key).toBe('EXP_BULK_USD_FORWARDING');
  });

  it('maps BREAK_BULK cargo to BULK freight', () => {
    const key = resolver.resolve(
      booking({
        tradeDirection: 'IMPORT',
        freightType: 'CONTAINER',
        paymentCurrency: 'ETB',
        cargoType: { code: 'BREAK_BULK_GENERAL' } as CargoType,
        serviceType: undefined,
      }),
    );
    expect(key).toBe('IMP_BULK_ETB_TRANSPORT_ONLY');
  });

  it('resolves domestic container', () => {
    const key = resolver.resolve(
      booking({
        tradeDirection: 'DOMESTIC',
        freightType: 'CONTAINER',
        paymentCurrency: 'USD',
        serviceType: undefined,
      }),
    );
    expect(key).toBe('DOM_CON_USD_TRANSPORT_ONLY');
  });
});
