<?php

namespace Gaco\SnapBi\Traits;

trait BuildResponseCode
{
    /**
     * Build response code with format: {httpCode}{serviceCode}{caseCode}
     * 
     * Format: 3 digit HTTP code + 2 digit service code + 2 digit case code
     * Example: 4012400 = 401 (HTTP) + 24 (Service) + 00 (Case)
     * 
     * @param int $httpCode HTTP status code (3 digits: 200, 400, 401, 403, 404, etc.)
     * @param string $serviceCode Service code (2 digits: 24, 25, 26, 29, 32, 33, 34, 73)
     * @param int $caseCode Case code (2 digits: 00-23)
     * @return string Response code (7 digits total)
     */
    public function buildCode(
        int $httpCode,
        string $serviceCode,
        int $caseCode
    ): string {
        // Ensure service code is 2 digits (pad left with 0 if needed)
        $serviceCode = str_pad($serviceCode, 2, '0', STR_PAD_LEFT);

        return sprintf(
            "%03d%s%02d",
            $httpCode,
            $serviceCode,
            $caseCode
        );
    }
}
