<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ParentProfile extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'user_id',
        'phone',
        'address_line1',
        'address_line2',
        'town',
        'postcode',
        'country',
        'notes',
    ];

    /**
     * Link back to the user account for this parent.
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    /**
     * Optional: link to billing accounts where this parent is primary.
     */
    public function billingAccounts()
    {
        return $this->hasMany(BillingAccount::class, 'primary_parent_user_id', 'user_id');
    }
	
	
	public function students(): BelongsToMany
	{
		return $this->belongsToMany(
				StudentProfile::class,
				'parent_student',
				'parent_profile_id',  // this model's FK on the pivot
				'student_profile_id'  // related model's FK on the pivot
			)
			->withPivot('relationship', 'notes')
			->withTimestamps();
	}
	
	public function parentProfile(): HasOne
	{
		return $this->hasOne(ParentProfile::class);
	}
}
