<?php
namespace App\Models\Entities;
use CodeIgniter\Model;

class NaverRawStagingModel extends Model {
    protected $table = 'naver_raw_staging';
    protected $allowedFields = ['atcl_no', 'verification_type', 'request_type', 'raw_json'];

    // 데이터를 넣기 전 자동으로 json_encode 실행
    protected $beforeInsert = ['encodeJson'];
    protected $beforeUpdate = ['encodeJson'];

    protected function encodeJson(array $data) {
        if (isset($data['data']['raw_json']) && is_array($data['data']['raw_json'])) {
            $data['data']['raw_json'] = json_encode($data['data']['raw_json'], JSON_UNESCAPED_UNICODE);
        }
        return $data;
    }
}