package com.sino.mci.crm.controller;

import com.sino.mci.crm.dto.CreateTagRequest;
import com.sino.mci.crm.dto.UpdateTagRequest;
import com.sino.mci.crm.service.TagService;
import com.sino.mci.shared.web.ApiResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/tag")
@RequiredArgsConstructor
public class TagController {

    private final TagService tagService;

    @PostMapping
    public ApiResponse<?> createTag(
            @RequestHeader("X-Tenant-Code") String tenantCode,
            @Valid @RequestBody CreateTagRequest request) {
        return ApiResponse.ok(tagService.createTag(tenantCode, request));
    }

    @GetMapping("/list")
    public ApiResponse<?> listTags(@RequestHeader("X-Tenant-Code") String tenantCode) {
        return ApiResponse.ok(tagService.listTags(tenantCode));
    }

    @PutMapping("/{id}")
    public ApiResponse<?> updateTag(
            @RequestHeader("X-Tenant-Code") String tenantCode,
            @PathVariable Long id,
            @Valid @RequestBody UpdateTagRequest request) {
        return ApiResponse.ok(tagService.updateTag(tenantCode, id, request));
    }

    @DeleteMapping("/{id}")
    public ApiResponse<?> deleteTag(
            @RequestHeader("X-Tenant-Code") String tenantCode,
            @PathVariable Long id) {
        tagService.deleteTag(tenantCode, id);
        return ApiResponse.ok();
    }
}
