<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Product extends Model
{
    use HasFactory;

    protected $table = 'products';

    protected $fillable = [
        'code',
        'brand',
        'product_name',
        'category',
        'type',
        'provider_price',
        'profit',
        'selling_price',
        'description',
        'provider_name',
        'status',
    ];

    protected $casts = [
        'provider_price' => 'integer',
        'profit'         => 'integer',
        'selling_price'  => 'integer',
    ];

    public function getSellingPriceFormattedAttribute(): string
    {
        return 'Rp ' . number_format($this->selling_price, 0, ',', '.');
    }

    public function getProviderPriceFormattedAttribute(): string
    {
        return 'Rp ' . number_format($this->provider_price, 0, ',', '.');
    }

    public function getProfitFormattedAttribute(): string
    {
        return 'Rp ' . number_format($this->profit, 0, ',', '.');
    }
}