import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace MallPropertyApi {
  /** 商品属性 */
  export interface Property {
    id?: number; // 属性编号
    name: string; // 名称
    remark?: string; // 备注
  }

  /** 属性值 */
  export interface PropertyValue {
    id?: number; // 属性值编号
    propertyId?: number; // 属性项的编号
    name: string; // 名称
    remark?: string; // 备注
  }
}

/** 创建属性项 */
export function createProperty(data: MallPropertyApi.Property) {
  return requestClient.post('/product/property/create', data);
}

/** 更新属性项 */
export function updateProperty(data: MallPropertyApi.Property) {
  return requestClient.put('/product/property/update', data);
}

/** 删除属性项 */
export function deleteProperty(id: number) {
  return requestClient.delete(`/product/property/delete?id=${id}`);
}

/** 获得属性项 */
export function getProperty(id: number) {
  return requestClient.get<MallPropertyApi.Property>(
    `/product/property/get?id=${id}`,
  );
}

/** 获得属性项分页 */
export function getPropertyPage(params: PageParam) {
  return requestClient.get<PageResult<MallPropertyApi.Property>>(
    '/product/property/page',
    { params },
  );
}

/** 获得属性项精简列表 */
export function getPropertySimpleList() {
  return requestClient.get<MallPropertyApi.Property[]>(
    '/product/property/simple-list',
  );
}

/** 获得属性值分页 */
export function getPropertyValuePage(params: PageParam) {
  return requestClient.get<PageResult<MallPropertyApi.PropertyValue>>(
    '/product/property/value/page',
    { params },
  );
}

/** 获得属性值 */
export function getPropertyValue(id: number) {
  return requestClient.get<MallPropertyApi.PropertyValue>(
    `/product/property/value/get?id=${id}`,
  );
}

/** 创建属性值 */
export function createPropertyValue(data: MallPropertyApi.PropertyValue) {
  return requestClient.post('/product/property/value/create', data);
}

/** 更新属性值 */
export function updatePropertyValue(data: MallPropertyApi.PropertyValue) {
  return requestClient.put('/product/property/value/update', data);
}

/** 删除属性值 */
export function deletePropertyValue(id: number) {
  return requestClient.delete(`/product/property/value/delete?id=${id}`);
}

/** 获得属性值精简列表 */
export function getPropertyValueSimpleList(propertyId: number) {
  return requestClient.get<MallPropertyApi.PropertyValue[]>(
    '/product/property/value/simple-list',
    {
      params: { propertyId },
    },
  );
}
