package com.example.demo.common;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class FinanceController {

    private final FinanceService financeService;
    private final AppDefaultsProperties defaults;

    public FinanceController(FinanceService financeService, AppDefaultsProperties defaults) {
        this.financeService = financeService;
        this.defaults = defaults;
    }

    @GetMapping("/api/finance/categories")
    public ResponseEntity<?> listCategories(@RequestHeader(name = "X-Shop-Id", required = false) Long shopId) {
        Long sid = (shopId == null ? defaults.getShopId() : shopId);
        Map<String, Object> body = financeService.getCategories(sid);
        return ResponseEntity.ok(body);
    }
}


