<?php

namespace App\Http\Controllers\Api\Company;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\CompanyMetric;

class CompanyMetricController extends Controller
{
    public function index($companyId)
    {
        return CompanyMetric::where('company_id',$companyId)->get();
    }

    public function store(Request $request)
    {
        $data = $request->validate([
            'company_id' => 'required',
            'metric_key' => 'required',
            'metric_value' => 'required'
        ]);

        return CompanyMetric::updateOrCreate(
            [
                'company_id'=>$request->company_id,
                'metric_key'=>$request->metric_key
            ],
            $data
        );
    }
}   