import { createCrudRoutes } from '@d8d/shared-crud';
import { authMiddleware } from '@d8d/auth-module-mt';
import { GoodsMt } from '../entities/goods.entity.mt';
import { UserGoodsSchema, UserCreateGoodsDto, UserUpdateGoodsDto } from '../schemas/user-goods.schema.mt';
import { FileMt } from '@d8d/file-module-mt';

export const userGoodsRoutesMt = createCrudRoutes({
  entity: GoodsMt,
  createSchema: UserCreateGoodsDto,
  updateSchema: UserUpdateGoodsDto,
  getSchema: UserGoodsSchema,
  listSchema: UserGoodsSchema,
  searchFields: ['name', 'instructions'],
  relations: ['category1', 'category2', 'category3', 'supplier', 'imageFile.uploadUser', 'slideImages.uploadUser'],
  middleware: [authMiddleware],
  userTracking: {
    createdByField: 'createdBy',
    updatedByField: 'updatedBy'
  },
  relationFields: {
    slideImageIds: {
      relationName: 'slideImages',
      targetEntity: FileMt,
      joinTableName: 'goods_slide_images'
    }
  },
  dataPermission: {
    enabled: true,
    userIdField: 'createdBy'
  },
  tenantOptions: {
    enabled: true,
    tenantIdField: 'tenantId'
  }
});