import GraphQLService from './GraphQLService';

export interface CityData {
    CityFind?: {
        rows?:{
            id :number,
            name :string,
            state_id : number
        }[]
    };
}

export interface StateData {
    StateFind?: {
        rows?:{
            id :number,
            name :string,
            state_id : number
        }[]
    };
}

export interface Country{
    id :number,
    name :string,
}

export interface CountryData {
    CountryFind?: {
        rows?:Country[]
    };
}
export interface MasterServiceType {
    GetCountry: () => Promise<any>;
  }

export interface MasterServiceType2 {
    CountryFind: { rows: string[] };
}
class MasterService extends GraphQLService {
    constructor() {
      super();
    }

    GetCity(state_id :number): Promise<CityData |null | undefined> {
        const Query = `query Rows($filter: CityFindInput!) {
                        CityFind(filter: $filter) {
                            rows {
                            id
                            name
                            state_id
                            }
                        }
                    }
                    `;
    
        const variables = {
          "filter": {
                "where": [
                {
                    "state_id": {
                        "equal": `${state_id}`
                    }
                }
                ],
                "order": {
                    "id": "DESC"
                },
                "take": 0
            }
        };
        return this.execute<CityData>(Query, variables); 
      }

      GetState(country_id :number): Promise<StateData |null | undefined> {
        const Query = `query Rows($filter: StateFindInput!) {
                        StateFind(filter: $filter) {
                            rows {
                            id
                            name
                            country_id
                            }
                        }
                    }
                    `;
    
        const variables = {
          "filter": {
                "where": [
                {
                    "country_id": {
                        "equal": `${country_id}`
                    }
                }
                ],
                "order": {
                    "id": "DESC"
                },
                "take": 0
            }
        };
        return this.execute<StateData>(Query, variables); 
      }

      GetCountry(): Promise<CountryData |null | undefined> {
        const Query = `query Rows($filter: CountryFindInput!) {
                        CountryFind(filter: $filter) {
                            rows {
                            id
                            name
                            }
                        }
                    }
                    `;
    
        const variables = {
          "filter": {
                "order": {
                    "id": "DESC"
                },
                "take": 0
            }
        };
        return this.execute<CountryData>(Query, variables); 
      }
}
const masterInstance = new MasterService();
export default masterInstance;