<?php

namespace App\Models;

use CodeIgniter\Model;

class StockCountLineModel extends Model
{
    protected $table         = 'stock_count_lines';
    protected $primaryKey    = 'id';
    protected $returnType    = 'array';
    protected $useTimestamps = false;

    protected $allowedFields = [
        'stock_count_id', 'product_id', 'system_qty', 'counted_qty', 'variance', 'notes', 'sort_order', 'created_at',
    ];

    public function getForCount(int $countId): array
    {
        return $this->select('stock_count_lines.*, products.name AS product_name, products.sku')
            ->join('products', 'products.id = stock_count_lines.product_id', 'left')
            ->where('stock_count_id', $countId)
            ->orderBy('sort_order', 'ASC')
            ->orderBy('id', 'ASC')
            ->findAll();
    }
}
