declare namespace MasterModel {
  interface SearchThingPaginationBody<T = SearchThingMetadata>
    extends SearchPaginationBody {
    order?: string;
    metadata?: T;
  }

  interface SearchThingMetadata {
    external_id?: string;
    state_level?: string; // vd: "normal,warning,critical,sos"
    /** kết nối */
    connected?: boolean;
    group_id?: string; // "id1,id2,id3"
  }

  // Thing
  interface ThingReponseMetadata {
    address?: string;
    alarm_list?: string;
    cfg_channel_id?: string;
    connected?: boolean;
    ctrl_channel_id?: string;
    data_channel_id?: string;
    enduser?: string;
    external_id?: string;
    group_id?: string;
    req_channel_id?: string;
    state?: string;
    state_level?: number;
    state_updated_time?: number;
    type?: string;
    updated_time?: number;
    uptime?: number;
    lat?: string;
    lng?: string;
  }

  interface ThingsResponse<
    T extends ThingReponseMetadata = ThingReponseMetadata,
  > extends PaginationReponse {
    metadata?: ThingsResponseMetadata;
    things?: Thing<T>[];
  }

  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<T extends ThingReponseMetadata = ThingReponseMetadata> {
    id?: string;
    name?: string;
    key?: string;
    metadata?: T;
  }

  // Thing Policy
  interface ThingPolicyResponse extends PaginationReponse {
    metadata?: null;
    things?: ThingPolicy[];
  }

  interface ThingPolicy {
    policies?: Policy[];
    thing_id?: string;
    thing_name?: string;
    external_id?: string;
  }

  type Policy = 'read' | 'delete' | 'write';
}
