import { UserId } from "@/server/user/domain/models";
import { DeleteTool, Tool, UserTool, UserToolQuery } from "../domain/models";
import { ToolService } from "./tool-service-definition";
import { defaultToolService } from "./tool-service-impl";
import { DeleteUserToolDto } from "./dto";
class ToolFacadeImpl implements ToolService{
constructor(
private toolService:ToolService
){}
getAllTools(): Promise<Tool[]> {
return this.toolService.getAllTools()
}
getUserTools(userId: UserId): Promise<UserToolQuery[]> {
return this.toolService.getUserTools(userId)
}
createTool(data: Tool, userId: UserId): Promise<Tool> {
return this.toolService.createTool(data,userId)
}
updateTools(data: Partial<Tool[]>, userId: UserId): Promise<Partial<Tool[]>> {
return this.toolService.updateTools(data,userId)
}
deleteTools(data: DeleteTool, userId: UserId): Promise<Tool[]> {
return this.toolService.deleteTools(data,userId)
}
async assignUserToolsToUser(data: UserTool[]): Promise<UserTool[]> {
try {
return await this.toolService.assignUserToolsToUser(data)
} catch (error) {
console.log('err asign tools',error)
throw new Error("Error to assign tools to user")
}
}
async updateAssignUserTools(data:UserTool[]): Promise<UserTool[]> {
try {
return await this.toolService.updateAssignUserTools(data)
} catch (error) {
console.log('err asign tools',error)
throw new Error("Error to update tools to user")
}
}
async deleteUserTools(data: DeleteUserToolDto[]): Promise<UserTool[]> {
try {
return await this.toolService.deleteUserTools(data)
} catch (error) {
throw new Error("Error deleting user tools")
}
}
}
export const toolServiceFacade = new ToolFacadeImpl(defaultToolService)