```
<?php
/*

<?php

use yii\db\ActiveRecord;

class Order extends ActiveRecord
{
    public const STATUS_PROCESSING   = 1;    // 0b00000001
    public const STATUS_PAID         = 2;    // 0b00000010
    public const STATUS_FAILED       = 4;    // 0b00000100
    public const STATUS_SHIPPED      = 8;    // 0b00001000
    public const STATUS_COMPLETED    = 16;   // 0b00010000
    public const STATUS_CANCELLATION = 32;   // 0b00100000
    public const STATUS_CANCELED     = 64;   // 0b01000000
    public const STATUS_REFUND       = 128;  // 0b10000000

    /**
     * @var int Bitmask of order status flags.
     */
    public int $status = self::STATUS_PROCESSING;

    /**
     * Validation rules.
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            ['status', 'default', 'value' => self::STATUS_PROCESSING],
            ['status', 'validateStatus'],
        ];
    }

    /**
     * Validate the status flags.
     *
     * @param string $attribute attribute name
     * @param array  $params    additional params
     */
    public function validateStatus(string $attribute, array $params): void
    {
        $validFlags = self::STATUS_PROCESSING | self::STATUS_PAID | self::STATUS_FAILED | 
                      self::STATUS_SHIPPED | self::STATUS_COMPLETED | self::STATUS_CANCELLATION | 
                      self::STATUS_CANCELED | self::STATUS_REFUND;

        // Check for invalid bits
        if (($this->$attribute & ~$validFlags) !== 0) {
            $this->addError($attribute, 'Status contains invalid flags.');
            return;
        }

        // Rule: Order cannot have both cancellation and canceled statuses
        $cancellationAndCanceled = self::STATUS_CANCELLATION | self::STATUS_CANCELED;
        if (($this->status & $cancellationAndCanceled) === $cancellationAndCanceled) {
            $this->addError($attribute, "Order cannot have both cancellation and canceled statuses.");
        }

        // Rule: Order cannot be both completed and in cancellation
        $completedAndCancellation = self::STATUS_COMPLETED | self::STATUS_CANCELLATION;
        if (($this->status & $completedAndCancellation) === $completedAndCancellation) {
            $this->addError($attribute, "Order cannot be both completed and in cancellation.");
        }

        // Rule: Shipped orders cannot be canceled
        $shippedAndCanceled = self::STATUS_SHIPPED | self::STATUS_CANCELED;
        if (($this->status & $shippedAndCanceled) === $shippedAndCanceled) {
            $this->addError($attribute, "Shipped orders cannot be canceled.");
        }
    }

    /**
     * Returns an array of status flags and their labels.
     *
     * @return array<int, string>
     */
    public static function getStatusLabels(): array
    {
        return [
            self::STATUS_PROCESSING   => \Yii::t('app', 'Processing'),
            self::STATUS_PAID         => \Yii::t('app', 'Paid'),
            self::STATUS_FAILED       => \Yii::t('app', 'Failed'),
            self::STATUS_SHIPPED      => \Yii::t('app', 'Shipped'),
            self::STATUS_COMPLETED    => \Yii::t('app', 'Completed'),
            self::STATUS_CANCELLATION => \Yii::t('app', 'Cancellation'),
            self::STATUS_CANCELED     => \Yii::t('app', 'Canceled'),
            self::STATUS_REFUND       => \Yii::t('app', 'Refund'),
        ];
    }

    /**
     * Returns a comma-separated string of all current status labels.
     *
     * @return string
     */
    public function getStatusLabel(): string
    {
        $labels = [];
        foreach (self::getStatusLabels() as $bit => $label) {
            if ($this->hasStatus($bit)) {
                $labels[] = $label;
            }
        }
        return empty($labels) ? \Yii::t('app', 'Unknown') : implode(', ', $labels);
    }

    /**
     * Attempts to return single status label matching exactly current status.
     * Falls back to "Unknown" if no exact match or multiple flags are set.
     *
     * @return string
     */
    public function getStatusList(): string
    {
        $statuses = self::getStatusLabels();

        return $statuses[$this->status] ?? \Yii::t('app', 'Unknown');
    }

    /**
     * Returns array of active status flags for checkboxes.
     *
     * No exclusivity enforced here; validation step forbids invalid combos.
     *
     * @return int[]
     */
    public function getStatusForCheckboxes(): array
    {
        $activeStatuses = [];
        foreach (self::getStatusLabels() as $flag => $label) {
            if ($this->hasStatus($flag)) {
                $activeStatuses[] = $flag;
            }
        }
        return $activeStatuses;
    }

    /**
     * Sets status flags from checkbox array.
     *
     * @param int[] $checkboxes array of status flags
     */
    public function setStatusFromCheckboxes(array $checkboxes): void
    {
        $this->status = 0;
        foreach ($checkboxes as $value) {
            $this->addStatus((int)$value);
        }
    }

    /**
     * Checks if a status flag or combination is set.
     *
     * @param int $status flag(s)
     * @return bool whether all bits are set
     */
    public function hasStatus(int $status): bool
    {
        return ($this->status & $status) === $status;
    }

    /**
     * Adds a status flag by bitwise OR.
     *
     * @param int $status flag(s)
     */
    public function addStatus(int $status): void
    {
        $this->status |= $status;
    }

    /**
     * Removes a status flag by bitwise AND NOT.
     *
     * @param int $status flag(s)
     */
    public function removeStatus(int $status): void
    {
        $this->status &= ~$status;
    }

    /*
     * Convenience boolean getters for each status.
     */

    public function isProcessing(): bool
    {
        return $this->hasStatus(self::STATUS_PROCESSING);
    }

    public function isPaid(): bool
    {
        return $this->hasStatus(self::STATUS_PAID);
    }

    public function isFailed(): bool
    {
        return $this->hasStatus(self::STATUS_FAILED);
    }

    public function isShipped(): bool
    {
        return $this->hasStatus(self::STATUS_SHIPPED);
    }

    public function isCompleted(): bool
    {
        return $this->hasStatus(self::STATUS_COMPLETED);
    }

    public function isCancellation(): bool
    {
        return $this->hasStatus(self::STATUS_CANCELLATION);
    }

    public function isCanceled(): bool
    {
        return $this->hasStatus(self::STATUS_CANCELED);
    }

    public function isRefund(): bool
    {
        return $this->hasStatus(self::STATUS_REFUND);
    }

    /*
     * Convenience setters for statuses.
     */

    public function setProcessing(): void
    {
        $this->addStatus(self::STATUS_PROCESSING);
    }

    public function setPaid(): void
    {
        $this->addStatus(self::STATUS_PAID);
    }

    public function setFailed(): void
    {
        $this->addStatus(self::STATUS_FAILED);
    }

    public function setShipped(): void
    {
        $this->addStatus(self::STATUS_SHIPPED);
    }

    public function setCompleted(): void
    {
        $this->addStatus(self::STATUS_COMPLETED);
    }

    public function setCancellation(): void
    {
        $this->addStatus(self::STATUS_CANCELLATION);
    }

    public function setCanceled(): void
    {
        $this->addStatus(self::STATUS_CANCELED);
    }

    public function setRefund(): void
    {
        $this->addStatus(self::STATUS_REFUND);
    }

    /**
     * Stub for adding validation error.
     * Remove or override if used within Yii ActiveRecord.
     *
     * @param string $attribute
     * @param string $message
     */
    protected function addError(string $attribute, string $message): void
    {
        // simple stand-in for standalone use
        echo "Validation error on {$attribute}: {$message}\n";
    }
}
```



```
<?php

use yii\db\ActiveRecord;

class Message extends ActiveRecord
{
    public const STATUS_UNREAD    = 1;    // 0b00000001
    public const STATUS_READ      = 2;    // 0b00000010
    public const STATUS_IMPORTANT = 4;    // 0b00000100
    public const STATUS_RESOLVED  = 8;    // 0b00001000
    public const STATUS_SPAM      = 16;   // 0b00010000
    public const STATUS_ARCHIVED  = 32;   // 0b00100000
    public const STATUS_FLAGGED   = 64;   // 0b01000000
    public const STATUS_REPLIED   = 128;  // 0b10000000

    /**
     * @var int Bitmask of status flags.
     */
    public int $status = self::STATUS_UNREAD;

    /**
     * Validation rules.
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            ['status', 'default', 'value' => self::STATUS_UNREAD],
            ['status', 'validateStatus'],
        ];
    }

    /**
     * Validate the status flags.
     *
     * @param string $attribute
     * @param array $params
     */
    public function validateStatus(string $attribute, array $params): void
    {
        $validFlags = self::STATUS_UNREAD | self::STATUS_READ | self::STATUS_IMPORTANT | self::STATUS_RESOLVED |
                      self::STATUS_SPAM | self::STATUS_ARCHIVED | self::STATUS_FLAGGED | self::STATUS_REPLIED;

       // If any bit outside validFlags is set, invalid
        if (($this->$attribute & ~$validFlags) !== 0) {
            $this->addError($attribute, 'Status contains invalid flags.');
            return;
        }

        // Unread and Read conflict
        $unreadAndRead = self::STATUS_UNREAD | self::STATUS_READ;
        if (($this->status & $unreadAndRead) === $unreadAndRead) {
            $this->addError($attribute, 'Status cannot be both unread and read.');
        }

        // Important and Resolved conflict
        $importantAndResolved = self::STATUS_IMPORTANT | self::STATUS_RESOLVED;
        if (($this->status & $importantAndResolved) === $importantAndResolved) {
            $this->addError($attribute, 'Status cannot be both important and resolved.');
        }

        // Important and Spam conflict
        if ($this->hasStatus(self::STATUS_IMPORTANT) && $this->hasStatus(self::STATUS_SPAM)) {
            $this->addError($attribute, 'Status cannot be both important and spam.');
        }

        // Resolved and Spam conflict
        if ($this->hasStatus(self::STATUS_RESOLVED) && $this->hasStatus(self::STATUS_SPAM)) {
            $this->addError($attribute, 'Status cannot be both resolved and spam.');
        }

        // Archived and Spam conflict
        if ($this->hasStatus(self::STATUS_ARCHIVED) && $this->hasStatus(self::STATUS_SPAM)) {
            $this->addError($attribute, 'Status cannot be both archived and spam.');
        }
    }

    /**
     * Returns array of status flags and their labels.
     *
     * @return array<int, string>
     */
    public static function getStatusLabels(): array
    {
        return [
            self::STATUS_UNREAD    => \Yii::t('app', 'Unread'),
            self::STATUS_READ      => \Yii::t('app', 'Read'),
            self::STATUS_IMPORTANT => \Yii::t('app', 'Important'),
            self::STATUS_RESOLVED  => \Yii::t('app', 'Resolved'),
            self::STATUS_SPAM      => \Yii::t('app', 'Spam'),
            self::STATUS_ARCHIVED  => \Yii::t('app', 'Archived'),
            self::STATUS_FLAGGED   => \Yii::t('app', 'Flagged'),
            self::STATUS_REPLIED   => \Yii::t('app', 'Replied'),
        ];
    }

    /**
     * Get current status labels as comma separated string.
     *
     * @return string
     */
    public function getStatusLabel(): string
    {
        $labels = [];
        foreach (self::getStatusLabels() as $flag => $label) {
            if ($this->hasStatus($flag)) {
                $labels[] = $label;
            }
        }
        return empty($labels) ? \Yii::t('app', 'Unknown') : implode(', ', $labels);
    }

    /**
     * Returns an array of active status flags suitable for checkboxes.
     *
     * Enforces some mutual exclusions similar to your validation:
     * For example, cannot have both unread and read, includes only one.
     *
     * @return int[]
     */
    public function getStatusForCheckboxes(): array
    {
        $statuses = [];

        // Mutually exclusive group: Unread or Read
        if ($this->hasStatus(self::STATUS_UNREAD) && !$this->hasStatus(self::STATUS_READ)) {
            $statuses[] = self::STATUS_UNREAD;
        } elseif (!$this->hasStatus(self::STATUS_UNREAD) && $this->hasStatus(self::STATUS_READ)) {
            $statuses[] = self::STATUS_READ;
        }

        // Mutually exclusive: Important or Resolved
        if ($this->hasStatus(self::STATUS_IMPORTANT) && !$this->hasStatus(self::STATUS_RESOLVED)) {
            $statuses[] = self::STATUS_IMPORTANT;
        } elseif (!$this->hasStatus(self::STATUS_IMPORTANT) && $this->hasStatus(self::STATUS_RESOLVED)) {
            $statuses[] = self::STATUS_RESOLVED;
        }

        // Only add Spam if it's not conflicting (important, resolved, archived)
        // Spam conflicts are handled at validation, so just add if set
        if ($this->hasStatus(self::STATUS_SPAM)) {
            $statuses[] = self::STATUS_SPAM;
        }

        // Archived (not mutually exclusive with anything except spam, handled by validation)
        if ($this->hasStatus(self::STATUS_ARCHIVED)) {
            $statuses[] = self::STATUS_ARCHIVED;
        }

        // Flagged and Replied just add if set
        if ($this->hasStatus(self::STATUS_FLAGGED)) {
            $statuses[] = self::STATUS_FLAGGED;
        }

        if ($this->hasStatus(self::STATUS_REPLIED)) {
            $statuses[] = self::STATUS_REPLIED;
        }

        return array_unique($statuses);
    }

    /**
     * Set multiple statuses from an array (e.g. checkbox inputs).
     *
     * @param int[] $checkboxes
     */
    public function setStatusFromCheckboxes(array $checkboxes): void
    {
        $this->status = 0;
        foreach ($checkboxes as $flag) {
            $this->addStatus((int)$flag);
        }
    }

    /**
     * Checks if specific status flag(s) are set.
     *
     * @param int $flag
     * @return bool
     */
    public function hasStatus(int $flag): bool
    {
        return ($this->status & $flag) === $flag;
    }

    /**
     * Adds given status flag(s).
     *
     * @param int $flag
     */
    public function addStatus(int $flag): void
    {
        $this->status |= $flag;
    }

    /**
     * Removes given status flag(s).
     *
     * @param int $flag
     */
    public function removeStatus(int $flag): void
    {
        $this->status &= ~$flag;
    }

    /*
     * Convenience boolean status getters
     */

    public function isUnread(): bool   { return $this->hasStatus(self::STATUS_UNREAD); }
    public function isRead(): bool     { return $this->hasStatus(self::STATUS_READ); }
    public function isImportant(): bool{ return $this->hasStatus(self::STATUS_IMPORTANT); }
    public function isResolved(): bool { return $this->hasStatus(self::STATUS_RESOLVED); }
    public function isSpam(): bool     { return $this->hasStatus(self::STATUS_SPAM); }
    public function isArchived(): bool { return $this->hasStatus(self::STATUS_ARCHIVED); }
    public function isFlagged(): bool  { return $this->hasStatus(self::STATUS_FLAGGED); }
    public function isReplied(): bool  { return $this->hasStatus(self::STATUS_REPLIED); }

    /*
     * Convenience setters
     */

    public function setUnread(): void    { $this->addStatus(self::STATUS_UNREAD); }
    public function setRead(): void      { $this->addStatus(self::STATUS_READ); }
    public function setImportant(): void { $this->addStatus(self::STATUS_IMPORTANT); }
    public function setResolved(): void  { $this->addStatus(self::STATUS_RESOLVED); }
    public function setSpam(): void      { $this->addStatus(self::STATUS_SPAM); }
    public function setArchived(): void  { $this->addStatus(self::STATUS_ARCHIVED); }
    public function setFlagged(): void   { $this->addStatus(self::STATUS_FLAGGED); }
    public function setReplied(): void   { $this->addStatus(self::STATUS_REPLIED); }

    /**
     * Stub for addError to allow standalone validation.
     * Remove if used inside Yii ActiveRecord model.
     *
     * @param string $attribute
     * @param string $message
     * @return void
     */
    protected function addError(string $attribute, string $message): void
    {
        echo "Validation error on {$attribute}: {$message}\n";
    }
}
```
Can you create OrderQuery and MessageQuery that handles these two models and what I would need. This is what I 
have so far:

```
<?php
declare(strict_types=1);

namespace app\models\query;

use yii\db\ActiveQuery;

use app\models\Message;

/**
* This is the ActiveQuery class for [[Message]].
* @see app/models/Message
*/
class MessageQuery extends ActiveQuery
{
	/**
	* {@inheritdoc}
	* @return Cart[]|array
	*/
	public function all($db = null): array
	{
		return parent::all($db);
	}

	/**
	* {@inheritdoc}
	* @return Cart|array|null
	*/
	public function one($db = null)//: Leave blank, else error.
	{
		return parent::one($db);
	}
	
	/**
	* Id
	* @return app\models\query\MessageQuery
	*/
	public function id($id): MessageQuery
	{
		return $this->andWhere(['id' => $id]);
	}
	
	/**
	* Types
	* 
	* TYPE_CONTACT = 1;
	* TYPE_INQUIRY = 2;
	* TYPE_ORDER =3 ;
	*/
	public function contact(): MessageQuery
	{
		return $this->andWhere(['type' => [Message::TYPE_CONTACT]]);
	}
	
	public function inquiry(): MessageQuery
	{
		return $this->andWhere(['type' => [Message::TYPE_INQUIRY]]);
	}
	
	public function order(): MessageQuery
	{
		return $this->andWhere(['type' => [Message::TYPE_ORDER]]);
	}
	
	/*
	* Statuses
	*
	* STATUS_UNREAD = 1;
	* STATUS_READ = 2;
	* STATUS_IMPORTANT = 4;
	* STATUS_RESOLVED = 8;
	* STATUS_SPAM = 16;
	* STATUS_ARCHIVED = 32;
	* STATUS_FLAGGED = 64;
	*/
	public function unread(): MessageQuery
	{
		return $this->andWhere(['status' => [Message::STATUS_UNREAD]]);
	}
	
	public function read(): MessageQuery
	{
		return $this->andWhere(['status' => [Message::STATUS_READ]]);
	}
	
	public function important(): MessageQuery
	{
		return $this->andWhere(['status' => [Message::STATUS_IMPORTANT]]);
	}
	
	public function resolved(): MessageQuery
	{
		return $this->andWhere(['status' => [Message::STATUS_RESOLVED]]);
	}
	
	public function spam(): MessageQuery
	{
		return $this->andWhere(['status' => [Message::STATUS_SPAM]]);
	}
	
	public function archived(): MessageQuery
	{
		return $this->andWhere(['status' => [Message::STATUS_ARCHIVED]]);
	}
	
	public function flagged(): MessageQuery
	{
		return $this->andWhere(['status' => [Message::STATUS_FLAGGED]]);
	}
}
```

and 

```
<?php
declare(strict_types=1);

namespace app\models\query;

use yii\db\ActiveQuery;

use app\models\Order;

/**
* This is the ActiveQuery class for [[Order]].
* @see Order
*/
class OrderQuery extends ActiveQuery
{
	/**
	* {@inheritdoc}
	* @return Cart[]|array
	*/
	public function all($db = null): array
	{
		return parent::all($db);
	}

	/**
	* {@inheritdoc}
	* @return Cart|array|null
	*/
	public function one($db = null)//: Leave blank, else error.
	{
		return parent::one($db);
	}
	
	/**
	* Stripe Order Id
	* @return app\models\query\OrderQuery
	*/
	public function stripeId($id): OrderQuery
	{
		return $this->andWhere(['stripe_order_id' => $id]);
	}
	
	/**
	* Order Statuses
	* @return app\models\query\OrderQuery
	*
	* STATUS_PROCESSING = 1;
	* STATUS_PAID = 2;
	* STATUS_FAILED = 4;
	* STATUS_SHIPPED = 7;
	* STATUS_COMPLETED = 16;
	* STATUS_CANCELLATION = 32;
	* STATUS_CANCELED = 40;
	* STATUS_CANCELED = 64;
	* STATUS_REFUND = 128;
	*/
	public function processing(): OrderQuery
	{
		return $this->andWhere(['status' => Order::STATUS_PROCESSING]);
	}
	
	public function paid(): OrderQuery
	{
		return $this->andWhere(['status' => [Order::STATUS_PAID, Order::STATUS_COMPLETED]]);
	}
	
	public function failed(): OrderQuery
	{
		return $this->andWhere(['status' => [Order::STATUS_FAILED, Order::STATUS_CANCELED]]);
	}
	
	public function cancellation(): OrderQuery
	{
		return $this->andWhere(['status' => Order::STATUS_CANCELLATION]);
	}
}

```