declare namespace Model {
  interface LoginRequestBody {
    guid: string;
    email: string;
    password: string;
  }
  interface LoginResponse {
    enabled2fa: boolean;
    token?: string;
  }

  interface ProfileResponse {
    id?: string;
    email?: string;
    metadata?: ProfileMetadata;
  }

  interface ProfileMetadata {
    frontend_thing_id?: string;
    frontend_thing_key?: string;
    full_name?: string;
    phone_number?: string;
    user_type?: string;
  }

  interface GPSResponse {
    lat: number;
    lon: number;
    s: number;
    h: number;
    fishing: boolean;
    t: number;
  }
  // Banzone
  interface Zone {
    id?: string;
    name?: string;
    type?: number;
    conditions?: Condition[];
    enabled?: boolean;
    updated_at?: Date;
    geometry?: string;
    description?: string;
    province_code?: string;
  }

  interface Condition {
    max?: number;
    min?: number;
    type?: Type;
    to?: number;
    from?: number;
  }

  enum Type {
    LengthLimit = "length_limit",
    MonthRange = "month_range",
  }

  interface Geom {
    geom_type?: number;
    geom_poly?: string;
    geom_lines?: string;
    geom_point?: string;
    geom_radius?: number;
  }

  interface SosRequest {
    message?: string;
  }

  interface SosResponse {
    active: boolean;
    message?: string;
    started_at?: number;
  }

  // Trip
  // Body API trip
  interface TripListBody {
    name?: string;
    order?: string;
    dir?: "asc" | "desc";
    limit: number;
    offset: number;
    metadata?: TripRequestMetadata;
  }

  interface TripRequestMetadata {
    status?: string;
    from?: string;
    to?: string;
    ship_name?: string;
    reg_number?: string;
    province_code?: string;
    owner_id?: string;
    ship_id?: string;
    thing_id?: string;
  }

  interface TripsListResponse {
    total?: number;
    offset?: number;
    limit?: number;
    trips?: Trip[];
  }

  interface Trip {
    id: string;
    ship_id: string;
    ship_length: number;
    vms_id: string;
    name: string;
    fishing_gears: FishingGear[]; // Dụng cụ đánh cá
    crews?: TripCrews[]; // Thuyền viên
    departure_time: string; // ISO datetime string
    departure_port_id: number;
    arrival_time: string; // ISO datetime string
    arrival_port_id: number;
    fishing_ground_codes: number[];
    total_catch_weight: number | null;
    total_species_caught: number | null;
    trip_cost: TripCost[]; // Chi phí chuyến đi
    trip_status: number;
    approved_by: string;
    notes: string | null;
    fishing_logs: FishingLog[] | null; // tuỳ dữ liệu chi tiết có thể định nghĩa thêm
    sync: boolean;
  }

  // Dụng cụ đánh cá
  interface FishingGear {
    name: string;
    number: string;
  }
  // Thuyền viên
  interface TripCrews {
    TripID: string;
    PersonalID: string;
    role: string;
    joined_at: Date;
    left_at: Date | null;
    note: string | null;
    Person: TripCrewPerson;
  }
  interface TripCrewPerson {
    personal_id: string;
    name: string;
    phone: string;
    email: string;
    birth_date: Date; // ISO string (có thể chuyển sang Date nếu parse trước)
    note: string;
    address: string;
    created_at: Date;
    updated_at: Date;
  }

  // TripCrew Request Body
  interface NewTripCrewAPIRequest {
    trip_id: string;
    personal_id: string;
    role: "captain" | "crew";
  }
  interface UpdateTripCrewAPIRequest {
    trip_id: string;
    personal_id: string;
    role: "captain" | "crew";
    note: string;
  }
  interface NewCrewAPIRequest {
    personal_id: string;
    name: string;
    phone: string;
    email: string;
    birth_date: Date;
    note: string;
    address: string;
  }
  interface UpdateCrewAPIRequest {
    name: string;
    phone: string;
    email: string;
    birth_date: Date;
    //note: string;
    address: string;
  }

  // Chi phí chuyến đi
  interface TripCost {
    type: string;
    unit: string;
    amount: number;
    total_cost: number;
    cost_per_unit: number;
  }
  // Thông tin mẻ lưới
  interface FishingLog {
    fishing_log_id: string;
    trip_id: string;
    start_at: Date; // ISO datetime
    end_at: Date; // ISO datetime
    start_lat: number;
    start_lon: number;
    haul_lat: number;
    haul_lon: number;
    status: number;
    weather_description: string;
    info?: FishingLogInfo[]; // Thông tin cá
    sync: boolean;
  }
  // Thông tin cá
  interface FishingLogInfo {
    fish_species_id?: number;
    fish_name?: string;
    catch_number?: number;
    catch_unit?: string;
    fish_size?: number;
    fish_rarity?: number;
    fish_condition?: string;
    gear_usage?: string;
  }
  interface NewFishingLogRequest {
    trip_id: string;
    start_at: Date; // ISO datetime
    start_lat: number;
    start_lon: number;
    weather_description: string;
  }

  interface TripUpdateStateRequest {
    status: number;
    note?: string;
  }

  // API body interface for creating a new trip
  interface TripAPIBody {
    name: string;
    departure_time: string; // ISO string
    departure_port_id: number;
    arrival_time: string; // ISO string
    arrival_port_id: number;
    fishing_ground_codes: number[];
    fishing_gears: Array<{
      name: string;
      number: string;
    }>;
    trip_cost: Array<{
      type: string;
      amount: number;
      unit: string;
      cost_per_unit: number;
      total_cost: number;
    }>;
  }
  //Fish
  interface FishSpeciesResponse {
    id: number;
    name: string;
    scientific_name: string;
    group_name: string;
    species_code: string;
    note: string;
    default_unit: string;
    rarity_level: number;
    created_at: string;
    updated_at: string;
    is_deleted: boolean;
  }
  interface FishRarity {
    id: number;
    code: string;
    label: string;
    description: string;
    iucn_code: any;
    cites_appendix: any;
    vn_law: boolean;
  }

  // Seagateway Owner App
  // Thing
  interface SearchThingBody {
    offset?: number;
    limit?: number;
    order?: string;
    dir?: "asc" | "desc";
    name?: string;
    metadata?: any;
  }

  interface ThingsResponse {
    total?: number;
    offset?: number;
    limit?: number;
    order?: string;
    direction?: string;
    metadata?: ThingsResponseMetadata;
    things?: Thing[];
  }

  interface ThingsResponseMetadata {
    total_connected?: number;
    total_filter?: number;
    total_sos?: number;
    total_state_level_0?: number;
    total_state_level_1?: number;
    total_state_level_2?: number;
    total_thing?: number;
  }

  interface Thing {
    id?: string;
    name?: string;
    key?: string;
    metadata?: ThingMetadata;
  }

  interface ThingMetadata {
    address?: string;
    alarm_list?: string;
    basename?: string;
    cfg_channel_id?: string;
    cfg_id?: string;
    connected?: boolean;
    ctrl_channel_id?: string;
    data_channel_id?: string;
    enduser?: string;
    external_id?: string;
    gps?: string;
    gps_time?: string;
    group_id?: string;
    req_channel_id?: string;
    ship_group_id?: string;
    ship_id?: string;
    ship_length?: string;
    ship_name?: string;
    ship_power?: string;
    ship_reg_number?: string;
    ship_type?: string;
    sos?: string;
    sos_time?: string;
    state?: string;
    state_level?: number;
    state_updated_time?: number;
    trip_state?: string;
    type?: string;
    updated_time?: number;
    uptime?: number;
    zone_approaching_alarm_list?: string;
    zone_entered_alarm_list?: string;
    zone_fishing_alarm_list?: string;
  }

  // Ship
  interface ShipType {
    id?: number;
    name?: string;
    description?: string;
  }

  interface ShipGroup {
    id?: string;
    name?: string;
    owner_id?: string;
    description?: string;
  }

  interface AlarmPayload {
    offset: number;
    limit: number;
    order?: string;
    dir?: "asc" | "desc";
    name?: string;
    level?: number;
    thing_id?: string;
    confirmed?: boolean;
  }

  interface AlarmResponse {
    total?: number;
    limit?: number;
    order?: string;
    dir?: string;
    alarms?: Alarm[];
  }

  interface Alarm {
    name?: string;
    time?: number;
    level?: number;
    id?: string;
    confirmed?: boolean;
    confirmed_email?: string;
    confirmed_time?: number;
    confirmed_desc?: string;
    thing_id?: string;
    thing_name?: string;
    thing_type?: ThingType;
  }

  interface AlarmConfirmRequest {
    id: string;
    description?: string;
    thing_id: string;
    time: number;
  }

  interface ShipBodyRequest {
    name?: string;
    reg_number?: string;
    imo_number?: string;
    mmsi_number?: string;
    thing_id?: string;
    ship_type?: number;
    owner_id?: string;
    home_port?: number;
    ship_length?: number;
    ship_power?: number;
    ship_group_id?: string;
    fishing_license_number?: string;
    fishing_license_expiry_date?: Date;
  }
  interface ShipResponse {
    ships?: Ship[];
  }

  interface Ship {
    id?: string;
    thing_id?: string;
    owner_id?: string;
    name?: string;
    ship_type?: number;
    home_port?: number;
    ship_length?: number;
    ship_power?: number;
    reg_number?: string;
    imo_number?: string;
    mmsi_number?: string;
    fishing_license_number?: string;
    fishing_license_expiry_date?: Date;
    province_code?: string;
    ship_group_id?: string;
    created_at?: Date;
    updated_at?: Date;
  }

  interface PortResponse {
    total?: number;
    offset?: number;
    limit?: number;
    ports?: Port[];
  }

  interface Port {
    id?: number;
    name?: string;
    type?: Type;
    classification?: Classification;
    position_point?: string;
    has_origin_confirm?: boolean;
    province_code?: string;
    updated_at?: Date;
    is_deleted?: boolean;
  }

  enum Classification {
    ChưaXácĐịnh = "Chưa xác định",
    I = "I",
    Ii = "II",
  }

  enum Type {
    Fishing = "fishing",
  }

  // Groups
  interface GroupResponse {
    total?: number;
    level?: number;
    name?: string;
    groups?: Group[];
  }

  interface Group {
    id?: string;
    name?: string;
    owner_id?: string;
    description?: string;
    metadata?: GroupMetadata;
    level?: number;
    path?: string;
    children?: Child[];
    created_at?: Date;
    updated_at?: Date;
  }

  interface Child {
    id?: string;
    name?: string;
    owner_id?: string;
    parent_id?: string;
    description?: string;
    metadata?: GroupMetadata;
    level?: number;
    path?: string;
    children?: Child[];
    created_at?: Date;
    updated_at?: Date;
  }

  interface GroupMetadata {
    code?: string;
    short_name?: string;
  }
}
