import { createCrudRoutes } from '@d8d/shared-crud';
import { authMiddleware } from '@d8d/auth-module';
import { Supplier } from '../entities/supplier.entity';
import { UserSupplierSchema, CreateUserSupplierDto, UpdateUserSupplierDto } from '../schemas/user-supplier.schema';

export const userSupplierRoutes = createCrudRoutes({
  entity: Supplier,
  createSchema: CreateUserSupplierDto,
  updateSchema: UpdateUserSupplierDto,
  getSchema: UserSupplierSchema,
  listSchema: UserSupplierSchema,
  searchFields: ['name', 'username', 'realname'],
  middleware: [authMiddleware],
  userTracking: {
    createdByField: 'createdBy',
    updatedByField: 'updatedBy'
  },
  dataPermission: {
    enabled: true,
    userIdField: 'createdBy'
  }
});