```php
<?php

require_once '../../core/api_bootstrap.php';
require_once '../../services/crud_service.php';



require_once '../../core/employee_auth.php';
EmployeeAuth::check('manage_categories');

$data = Request::post();

try {

    Validator::required($data,[
        'category_id',
        'name',
        'short_description'
    ]);

    $db = new Database();
    $conn = $db->connect();

    $crud = new CrudService($conn);

    $category_id = (int)$data['category_id'];

    // Verify category exists
    $check = $conn->prepare("
        SELECT id FROM categories
        WHERE id = :id AND status = 1
        LIMIT 1
    ");

    $check->execute([':id'=>$category_id]);

    if(!$check->fetch()){
        Response::error("Invalid category");
    }


    $name = Helper::sanitize($data['name']);

    $slug = $data['slug'] ?? '';

    if(empty($slug)){
        $slug = Slug::generateUnique(
            'sub_categories',
            'slug',
            $name
        );
    }


    $insertData = [

        "category_id"=>$category_id,
        "name"=>$name,
        "slug"=>$slug,
        "short_description"=>$data['short_description'],
        "description"=>$data['description'] ?? null,
        "seo_content"=>$data['seo_content'] ?? null,
        "meta_title"=>$data['meta_title'] ?? null,
        "meta_description"=>$data['meta_description'] ?? null,
        "meta_keywords"=>$data['meta_keywords'] ?? null,
        "schema_markup"=>$data['schema_markup'] ?? null,
        "status"=>$data['status'] ?? 1

    ];


    $icon  = Upload::image('icon','subcategories');
    $image = Upload::image('image','subcategories');

    if($icon){
        $insertData['icon']=$icon;
    }

    if($image){
        $insertData['image']=$image;
    }


    $subcategory_id = $crud->create('sub_categories',$insertData);


    Logger::activity(
        ApiAuth::employeeId(),
        "create",
        "sub_categories",
        $subcategory_id,
        ApiAuth::ip()
    );


    Response::success([
        "subcategory_id"=>$subcategory_id
    ],"Subcategory created");


}
catch(Exception $e){

    Logger::log("system.log",$e->getMessage());

    Response::error("Server error",500);

}