import { ACTIVE_CODE, BAN_THEO_DOT } from './constant';
const getCustomQuery = ({ searchValue, isInCampaign, type, }) => {
    const queryArr = [];
    if (searchValue) {
        queryArr.push(` _or:[
        {name: { _ilike: "%${searchValue}%" }}
        {name_unaccent: { _ilike: "%${searchValue}%" }}
       {code: { _ilike: "%${searchValue}%" }}
    ]`);
    }
    if (isInCampaign && type === 'PRODUCT') {
        queryArr.push(`store_product_sale_type:{
        code:{_eq: "${BAN_THEO_DOT}"}
      }`);
    }
    if (isInCampaign && type === 'BUNDLE') {
        queryArr.push(` store_bundle_sale_type:{
        code:{_eq: "${BAN_THEO_DOT}"}
      }`);
    }
    return queryArr.join(',');
};
export const countAllBundleAndProductQuery = (isInCampaign) => {
    return `
query getListProductQuery($school_id: Int!) {
    store_product_aggregate(
    where: {
     ${isInCampaign
        ? ` store_product_sale_type:{
        code:{_eq: "${BAN_THEO_DOT}"}
      }`
        : ''}, 
      store_product_status:{code:{_eq:"${ACTIVE_CODE}"}}
      deleted_at: {_is_null: true}, 
      school_id: {_eq: $school_id} 
      }) 
      {
        aggregate{
          count
        }
      }
      store_bundle_aggregate(
    where:{
      deleted_at:{_is_null: true}
      store_bundle_status:{code:{_eq: "${ACTIVE_CODE}"}}
      school_id:{_eq: $school_id}
     ${isInCampaign
        ? ` store_bundle_sale_type:{
        code:{_eq: "${BAN_THEO_DOT}"}
      }`
        : ''}
    }) {
     aggregate{
    count
  }
    }
  }

`;
};
export const getListBundleQuery = (searchValue, isInCampaign) => {
    return `
query getListBundleQuery($school_id: Int!, $school_year_id: Int!, $limit: Int!, $offset: Int!) {
    store_bundle(
    limit: $limit
    offset: $offset
    order_by:{id: asc}
    where:{
      deleted_at:{_is_null: true}
      store_bundle_status:{code:{_eq: "${ACTIVE_CODE}"}}
      school_id:{_eq: $school_id}
      ${getCustomQuery({ searchValue, isInCampaign, type: 'BUNDLE' })}
    }) {
      bundle_id: id
      name
      image
      price_type
      status: store_bundle_status {
        name
        code
      }
      tuition_fee_type_of_service {
        description
        tuition_fee_project_codes(where: {deleted_at: {_is_null: true}, school_year_id: {_eq: $school_year_id}}) {
          code
        }
      }
      store_bundle_products( where: {deleted_at: {_is_null: true}store_product: {deleted_at: {_is_null: true}}}) {
        store_bundle_product_attribute_values(
          where: {
            deleted_at: {_is_null:true} 
            store_product_attribute_value: {
              deleted_at:{_is_null:true}
            }
          }) {
          store_product_attribute_value {
            price
          }
        }
      }
    }
  }
`;
};
export const getListProductQuery = (searchValue, isInCampaign) => {
    return `
query getListProductQuery($school_id: Int!, $school_year_id: Int!, $limit: Int!, $offset: Int!) {
    store_product(
    limit: $limit
    offset: $offset
    order_by:{id: asc}
    where: {
      ${getCustomQuery({ searchValue, isInCampaign, type: 'PRODUCT' })}
      store_product_status:{code:{_eq:"${ACTIVE_CODE}"}}
      deleted_at: {_is_null: true}, 
      school_id: {_eq: $school_id} 
      }) 
      {
        product_id: id
        name
        image
        status: store_product_status {
          name
          code
        }
       tuition_fee_type_of_service {
          description
          tuition_fee_project_codes(where: {deleted_at: {_is_null: true}, school_year_id: {_eq: $school_year_id}}) {
            code
          }
        }
        store_product_attributes(where:{ deleted_at: {_is_null: true}}) {
          store_product_attribute_values_aggregate(where:{ deleted_at: {_is_null: true}}) {
            aggregate {
              min {
                price
              }
              max {
                price
              }
            }
          }
        }
      }
  }
  `;
};
//# sourceMappingURL=query.js.map