-- ============================================================
-- uapi SQL Configuration for Volcengine Ark Real Person Portrait APIs
-- Execute against the Sage database to register these APIs
-- ============================================================

-- 1. Register Volcengine Ark as an external application (upapp)
-- The AK/SK signing is handled by the dynamic_func
INSERT INTO upapp (id, name, description, ownerid, apisetid, secretkey, baseurl, myappid, dynamic_func, auth_apiname) VALUES (
    'volcengine_ark',
    'volcengine_ark',
    '火山方舟 - 真人人像素材管理API (AK/SK签名)',
    '0',
    '',
    '',
    'https://open.volcengineapi.com',
    '',
    'volcengine_ark_sign',
    NULL
) ON DUPLICATE KEY UPDATE description=VALUES(description), baseurl=VALUES(baseurl);

-- 2. Register API Key storage (upappkey)
-- Replace <YOUR_AK> and <YOUR_SK> with actual Volcengine credentials
-- The apikey = Access Key, secretkey = Secret Key
-- INSERT INTO upappkey (id, upappid, ownerid, myappid, apikey, secretkey) VALUES (
--     'volcengine_ark_key_1',
--     'volcengine_ark',
--     '<owner_user_id>',
--     '',
--     password_encode('<YOUR_ACCESS_KEY>'),
--     password_encode('<YOUR_SECRET_KEY>')
-- );

-- 3. Input/Output definitions (uapiio)

-- CreateVisualValidateSession IO
INSERT INTO uapiio (id, name, description, input_fields) VALUES (
    'volc_cvvs_io',
    '创建真人认证会话',
    '拉起H5真人认证页',
    '{"CallbackURL": {"type": "string", "required": true, "description": "回调URL"}, "ProjectName": {"type": "string", "required": false, "default": "default"}}'
) ON DUPLICATE KEY UPDATE description=VALUES(description);

-- GetVisualValidateResult IO
INSERT INTO uapiio (id, name, description, input_fields) VALUES (
    'volc_gvvr_io',
    '获取真人认证结果',
    '查询认证创建的Asset Group ID',
    '{"BytedToken": {"type": "string", "required": true}, "ProjectName": {"type": "string", "required": false, "default": "default"}}'
) ON DUPLICATE KEY UPDATE description=VALUES(description);

-- CreateAsset IO
INSERT INTO uapiio (id, name, description, input_fields) VALUES (
    'volc_create_asset_io',
    '创建素材资产',
    '上传素材到真人认证组合',
    '{"GroupId": {"type": "string", "required": true}, "URL": {"type": "string", "required": true}, "AssetType": {"type": "string", "required": true, "options": ["Image","Video","Audio"]}, "Name": {"type": "string", "required": false}, "ProjectName": {"type": "string", "required": false, "default": "default"}}'
) ON DUPLICATE KEY UPDATE description=VALUES(description);

-- GetAsset IO
INSERT INTO uapiio (id, name, description, input_fields) VALUES (
    'volc_get_asset_io',
    '获取素材信息',
    '查询单个素材资产状态和信息',
    '{"Id": {"type": "string", "required": true}, "ProjectName": {"type": "string", "required": false, "default": "default"}}'
) ON DUPLICATE KEY UPDATE description=VALUES(description);

-- ListAssets IO
INSERT INTO uapiio (id, name, description, input_fields) VALUES (
    'volc_list_assets_io',
    '查询素材列表',
    '分页查询素材资产列表',
    '{"Filter": {"type": "object", "required": false}, "PageNumber": {"type": "integer", "default": 1}, "PageSize": {"type": "integer", "default": 10}, "SortBy": {"type": "string", "default": "CreateTime"}, "SortOrder": {"type": "string", "default": "Desc"}}'
) ON DUPLICATE KEY UPDATE description=VALUES(description);

-- ListAssetGroups IO
INSERT INTO uapiio (id, name, description, input_fields) VALUES (
    'volc_list_groups_io',
    '查询素材组合列表',
    '分页查询素材组合列表',
    '{"Filter": {"type": "object", "required": false}, "PageNumber": {"type": "integer", "default": 1}, "PageSize": {"type": "integer", "default": 10}}'
) ON DUPLICATE KEY UPDATE description=VALUES(description);

-- GetAssetGroup IO
INSERT INTO uapiio (id, name, description, input_fields) VALUES (
    'volc_get_group_io',
    '获取素材组合信息',
    '查询单个素材组合',
    '{"Id": {"type": "string", "required": true}, "ProjectName": {"type": "string", "required": false, "default": "default"}}'
) ON DUPLICATE KEY UPDATE description=VALUES(description);

-- UpdateAsset IO
INSERT INTO uapiio (id, name, description, input_fields) VALUES (
    'volc_update_asset_io',
    '更新素材信息',
    '更新素材资产名称等',
    '{"Id": {"type": "string", "required": true}, "Name": {"type": "string"}, "ProjectName": {"type": "string", "default": "default"}}'
) ON DUPLICATE KEY UPDATE description=VALUES(description);

-- UpdateAssetGroup IO
INSERT INTO uapiio (id, name, description, input_fields) VALUES (
    'volc_update_group_io',
    '更新素材组合',
    '更新素材组合信息',
    '{"Id": {"type": "string", "required": true}, "Name": {"type": "string"}, "Title": {"type": "string"}, "Description": {"type": "string"}, "ProjectName": {"type": "string", "default": "default"}}'
) ON DUPLICATE KEY UPDATE description=VALUES(description);

-- DeleteAsset IO
INSERT INTO uapiio (id, name, description, input_fields) VALUES (
    'volc_delete_asset_io',
    '删除素材',
    '删除单个素材资产',
    '{"Id": {"type": "string", "required": true}, "ProjectName": {"type": "string", "default": "default"}}'
) ON DUPLICATE KEY UPDATE description=VALUES(description);

-- DeleteAssetGroup IO
INSERT INTO uapiio (id, name, description, input_fields) VALUES (
    'volc_delete_group_io',
    '删除素材组合',
    '删除指定素材组合',
    '{"Id": {"type": "string", "required": true}, "ProjectName": {"type": "string", "default": "default"}}'
) ON DUPLICATE KEY UPDATE description=VALUES(description);


-- 4. API definitions (uapi)
-- NOTE: All APIs use POST method with Action/Version in query string
-- The dynamic_func 'volcengine_ark_sign' handles AK/SK HMAC signing

-- CreateVisualValidateSession
INSERT INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
    'volc_cvvs',
    'volcengine_ark',
    'createVisualValidateSession',
    '创建真人认证会话',
    '拉起H5真人认证页，返回H5Link和BytedToken',
    '0',
    'false',
    '/?Action=CreateVisualValidateSession&Version=2024-01-01',
    'POST',
    'BytedToken',
    '{"Content-Type":"application/json","Host":"open.volcengineapi.com"}',
    NULL,
    '{{jsondata}}',
    '{{response}}',
    'volc_cvvs_io'
) ON DUPLICATE KEY UPDATE title=VALUES(title), path=VALUES(path);

-- GetVisualValidateResult
INSERT INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
    'volc_gvvr',
    'volcengine_ark',
    'getVisualValidateResult',
    '获取真人认证结果',
    '获取认证创建的Asset Group ID',
    '0',
    'false',
    '/?Action=GetVisualValidateResult&Version=2024-01-01',
    'POST',
    'GroupId',
    '{"Content-Type":"application/json","Host":"open.volcengineapi.com"}',
    NULL,
    '{{jsondata}}',
    '{{response}}',
    'volc_gvvr_io'
) ON DUPLICATE KEY UPDATE title=VALUES(title), path=VALUES(path);

-- CreateAsset
INSERT INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
    'volc_create_asset',
    'volcengine_ark',
    'createAsset',
    '创建素材资产',
    '上传素材到真人认证组合(异步)',
    '0',
    'false',
    '/?Action=CreateAsset&Version=2024-01-01',
    'POST',
    'Id',
    '{"Content-Type":"application/json","Host":"open.volcengineapi.com"}',
    NULL,
    '{{jsondata}}',
    '{{response}}',
    'volc_create_asset_io'
) ON DUPLICATE KEY UPDATE title=VALUES(title), path=VALUES(path);

-- GetAsset
INSERT INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
    'volc_get_asset',
    'volcengine_ark',
    'getAsset',
    '获取素材信息',
    '查询单个素材资产',
    '0',
    'false',
    '/?Action=GetAsset&Version=2024-01-01',
    'POST',
    'Status',
    '{"Content-Type":"application/json","Host":"open.volcengineapi.com"}',
    NULL,
    '{{jsondata}}',
    '{{response}}',
    'volc_get_asset_io'
) ON DUPLICATE KEY UPDATE title=VALUES(title), path=VALUES(path);

-- ListAssets
INSERT INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
    'volc_list_assets',
    'volcengine_ark',
    'listAssets',
    '查询素材列表',
    '分页查询素材资产',
    '0',
    'false',
    '/?Action=ListAssets&Version=2024-01-01',
    'POST',
    'TotalCount',
    '{"Content-Type":"application/json","Host":"open.volcengineapi.com"}',
    NULL,
    '{{jsondata}}',
    '{{response}}',
    'volc_list_assets_io'
) ON DUPLICATE KEY UPDATE title=VALUES(title), path=VALUES(path);

-- ListAssetGroups
INSERT INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
    'volc_list_groups',
    'volcengine_ark',
    'listAssetGroups',
    '查询素材组合列表',
    '分页查询素材组合',
    '0',
    'false',
    '/?Action=ListAssetGroups&Version=2024-01-01',
    'POST',
    'TotalCount',
    '{"Content-Type":"application/json","Host":"open.volcengineapi.com"}',
    NULL,
    '{{jsondata}}',
    '{{response}}',
    'volc_list_groups_io'
) ON DUPLICATE KEY UPDATE title=VALUES(title), path=VALUES(path);

-- GetAssetGroup
INSERT INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
    'volc_get_group',
    'volcengine_ark',
    'getAssetGroup',
    '获取素材组合信息',
    '查询单个素材组合',
    '0',
    'false',
    '/?Action=GetAssetGroup&Version=2024-01-01',
    'POST',
    'Id',
    '{"Content-Type":"application/json","Host":"open.volcengineapi.com"}',
    NULL,
    '{{jsondata}}',
    '{{response}}',
    'volc_get_group_io'
) ON DUPLICATE KEY UPDATE title=VALUES(title), path=VALUES(path);

-- UpdateAsset
INSERT INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
    'volc_update_asset',
    'volcengine_ark',
    'updateAsset',
    '更新素材信息',
    '更新素材名称等',
    '0',
    'false',
    '/?Action=UpdateAsset&Version=2024-01-01',
    'POST',
    NULL,
    '{"Content-Type":"application/json","Host":"open.volcengineapi.com"}',
    NULL,
    '{{jsondata}}',
    '{{response}}',
    'volc_update_asset_io'
) ON DUPLICATE KEY UPDATE title=VALUES(title), path=VALUES(path);

-- UpdateAssetGroup
INSERT INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
    'volc_update_group',
    'volcengine_ark',
    'updateAssetGroup',
    '更新素材组合',
    '更新素材组合信息',
    '0',
    'false',
    '/?Action=UpdateAssetGroup&Version=2024-01-01',
    'POST',
    NULL,
    '{"Content-Type":"application/json","Host":"open.volcengineapi.com"}',
    NULL,
    '{{jsondata}}',
    '{{response}}',
    'volc_update_group_io'
) ON DUPLICATE KEY UPDATE title=VALUES(title), path=VALUES(path);

-- DeleteAsset
INSERT INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
    'volc_delete_asset',
    'volcengine_ark',
    'deleteAsset',
    '删除素材',
    '删除单个素材资产',
    '0',
    'false',
    '/?Action=DeleteAsset&Version=2024-01-01',
    'POST',
    NULL,
    '{"Content-Type":"application/json","Host":"open.volcengineapi.com"}',
    NULL,
    '{{jsondata}}',
    '{{response}}',
    'volc_delete_asset_io'
) ON DUPLICATE KEY UPDATE title=VALUES(title), path=VALUES(path);

-- DeleteAssetGroup
INSERT INTO uapi (id, upappid, name, title, description, need_auth, stream, path, httpmethod, chunk_match, headers, params, data, response, ioid) VALUES (
    'volc_delete_group',
    'volcengine_ark',
    'deleteAssetGroup',
    '删除素材组合',
    '删除指定素材组合',
    '0',
    'false',
    '/?Action=DeleteAssetGroup&Version=2024-01-01',
    'POST',
    NULL,
    '{"Content-Type":"application/json","Host":"open.volcengineapi.com"}',
    NULL,
    '{{jsondata}}',
    '{{response}}',
    'volc_delete_group_io'
) ON DUPLICATE KEY UPDATE title=VALUES(title), path=VALUES(path);
