import { Entity, Property, Enum, ManyToOne } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
import { DeliveryFeeTypeEnum, DeliveryMethodEnum } from '../interface/delivery';

@Entity({ tableName: 'deliveries' })
export class Delivery extends BaseEntity {
  @Enum(() => DeliveryMethodEnum)
  method!: DeliveryMethodEnum;

  @ManyToOne(() => Restaurant)
  restaurant!: Restaurant;

  @Property({ type: 'number', default: 0 })
  deliveryFee: number = 0;

  @Enum(() => DeliveryFeeTypeEnum)
  deliveryFeeType: DeliveryFeeTypeEnum = DeliveryFeeTypeEnum.FIXED;

  @Property({ type: 'number', default: 0 })
  perKilometerFee: number | null = null;

  @Property({ type: 'number', default: 0 })
  distanceBasedMinCost: number | null = null;

  @Property({ type: 'number', default: 0 })
  minOrderPrice: number = 0;

  @Property({ nullable: true })
  description?: string;

  @Property({ default: true })
  enabled: boolean = true;

  @Property({ type: 'integer', default: 0 })
  order: number = 0;
}
