import {
  AggregateRoot,
  CurrencyData,
  IDomainError,
  KeyValueMap,
  Language,
  Name,
  Result,
  UniqueID,
} from "@shared/contexts";
import { DealerLogotype } from "./DealerLogotype";
import { DealerStatus } from "./DealerStatus";

export interface IDealerProps {
  user_id: UniqueID;
  name: Name;
  //logo: string;
  language: Language;
  additionalInfo: KeyValueMap;
  status: DealerStatus;
  currency: CurrencyData;
  logo: DealerLogotype;
}

export interface IDealer {
  id: UniqueID;
  user_id: UniqueID;
  name: Name;
  language: Language;

  additionalInfo: KeyValueMap;
  status: DealerStatus;
  currency: CurrencyData;
  logo: DealerLogotype;

  getAcronym: () => string;
}

export class Dealer extends AggregateRoot<IDealerProps> implements IDealer {
  public static create(props: IDealerProps, id?: UniqueID): Result<Dealer, IDomainError> {
    const user = new Dealer(props, id);
    return Result.ok<Dealer>(user);
  }

  public static generateDealerNameAcronyn(dealerName: Name | string): string {
    return typeof dealerName === "string"
      ? Name.generateAcronym(dealerName)
      : dealerName.getAcronym();
  }

  get user_id(): UniqueID {
    return this.props.user_id;
  }

  get name(): Name {
    return this.props.name;
  }

  get language(): Language {
    return this.props.language;
  }

  get status(): DealerStatus {
    return this.props.status;
  }

  get additionalInfo(): KeyValueMap {
    return this.props.additionalInfo;
  }

  get currency(): CurrencyData {
    return this.props.currency;
  }

  get logo(): DealerLogotype {
    return this.props.logo;
  }

  public getAcronym(): string {
    return this.props.name.getAcronym();
  }
}
