import { PaginatedResponse } from '@edr/types';
import { FindManyOptions } from 'typeorm';
import { ListRatesQueryDto } from '../dto/list-rule-engine-query.dto';
import { Rate } from '../entities/rate.entity';

export interface IRatesRepository {
  findById(id: string): Promise<Rate | null>;
  findLiveRates(): Promise<Rate[]>;
  /**
   * LIVE rates with the yard / container / cargo relations eagerly joined, so
   * lanes can be rendered with human labels (contract rate schedule). Ordered
   * for a stable, readable schedule table.
   */
  findLiveRatesDetailed(): Promise<Rate[]>;
  findByPattern(pattern: {
    rateType: string;
    /** Omitted for singly-resolved rates — see the repository implementation. */
    rateUnit?: string;
    containerTypeId?: string | null;
    cargoTypeId?: string | null;
    tradeDirection?: string | null;
    originYardId?: string | null;
    destinationYardId?: string | null;
  }): Promise<Rate | null>;
  findAll(options?: FindManyOptions<Rate>): Promise<Rate[]>;
  findAndCount(options?: FindManyOptions<Rate>): Promise<[Rate[], number]>;
  findPaged(query: ListRatesQueryDto): Promise<PaginatedResponse<Rate>>;
  create(data: Partial<Rate>): Promise<Rate>;
  update(id: string, data: Partial<Rate>): Promise<Rate | null>;
  softDelete(id: string): Promise<void>;
}

export const RATES_REPOSITORY = Symbol('RATES_REPOSITORY');
