import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { StoreListVO, StoreInfoVO, StoreVO, StoreForm, StoreQuery, StoreStatusVO, SysStorePageBo, StoreOrderVO, StoreRenewReq } from '@/api/system/store/types';
import { StoreOrderQuery } from '../../../../template/api/system/store/types';

// 查询商户门店列表
export function listOnMerchantStoreInfo(): AxiosPromise<StoreListVO[]> {
    return request({
        url: '/system/store/listOnMerchantStoreInfo',
        method: 'get'
    });
}

// 查询用户关联的门店列表
export function listOnUser(userId?: string | number): AxiosPromise<any> {
    return request({
        url: '/system/store/listOnUser',
        method: 'get',
        params: { userId }
    });
}

// 查询门店详细信息
export function getStoreInfo(id: string | number): AxiosPromise<StoreInfoVO> {
    return request({
        url: '/system/store/getInfo',
        method: 'get',
        params: { id }
    });
};

/**
 * 查询门店管理列表
 * @param query
 * @returns {*}
 */

export const listStore = (query?: SysStorePageBo): AxiosPromise<StoreVO[]> => {
    return request({
        url: '/system/store/list',
        method: 'get',
        params: query
    });
};

/**
 * 查询门店管理详细
 * @param id
 */
export const getStore = (id: string | number): AxiosPromise<StoreVO> => {
    return request({
        url: '/system/store/' + id,
        method: 'get'
    });
};

/**
 * 新增门店管理
 * @param data
 */
export const addStore = (data: StoreForm) => {
    return request({
        url: '/system/store',
        method: 'post',
        data: data
    });
};

/**
 * 修改门店管理
 * @param data
 */
export const updateStore = (data: StoreForm) => {
    return request({
        url: '/system/store',
        method: 'put',
        data: data
    });
};

/**
 * 删除门店管理
 * @param id
 */
export const delStore = (id: string | number | Array<string | number>) => {
    return request({
        url: '/system/store/' + id,
        method: 'delete'
    });
};

/**
 * 获取状态列表
 */
export const listStoreStatus = (): AxiosPromise<StoreStatusVO[]> => {
  return request({
    url: '/system/store/listStatus',
    method: 'get'
  });
};

/**
 * 下单时查询门店列表
 * @param query
 * @returns {*}
 */
export const listStoreOnOrder = (query?: StoreOrderQuery): AxiosPromise<{ total: number; rows: StoreOrderVO[] }> => {
  return request({
    url: '/system/store/listOnOrder',
    method: 'get',
    params: query
  });
};

/**
 * 门店续期
 * @param data
 */
export const renewStore = (data: StoreRenewReq) => {
  return request({
    url: '/system/store/renew',
    method: 'put',
    data: data
  });
};

/**
 * 禁用门店
 * @param data
 */
export const banStore = (data: { id: string | number }) => {
  return request({
    url: '/system/store/ban',
    method: 'put',
    data: data
  });
};

/**
 * 启用门店
 * @param data
 */
export const enableStore = (data: { id: string | number }) => {
  return request({
    url: '/system/store/enable',
    method: 'put',
    data: data
  });
};
