--- /dev/null
+<?php
+
+declare(strict_types=1);
+
+namespace yii_app\records;
+
+use yii\db\ActiveQuery;
+
+/**
+ * Предсказание авторазметки товара из 1С.
+ *
+ * @property int $id
+ * @property string $product_id
+ * @property string|null $category
+ * @property string|null $subcategory
+ * @property string|null $species
+ * @property string|null $sort
+ * @property string|null $type
+ * @property int|null $size
+ * @property string|null $color
+ * @property float $confidence
+ * @property string $method
+ * @property int $status
+ * @property int|null $approved_by
+ * @property string $created_at
+ * @property string|null $updated_at
+ */
+class Products1cAutomarkPrediction extends \yii\db\ActiveRecord
+{
+ public const STATUS_PENDING = 0;
+ public const STATUS_APPROVED = 1;
+ public const STATUS_REJECTED = 2;
+
+ public const METHOD_RULE = 'rule';
+ public const METHOD_SIMILARITY = 'similarity';
+
+ public static function tableName(): string
+ {
+ return 'products_1c_automark_predictions';
+ }
+
+ public function rules(): array
+ {
+ return [
+ [['product_id', 'confidence', 'method', 'status'], 'required'],
+ [['product_id', 'category', 'subcategory', 'species', 'sort', 'type', 'color', 'method'], 'string', 'max' => 255],
+ [['size', 'status', 'approved_by'], 'integer'],
+ [['confidence'], 'number', 'min' => 0, 'max' => 1],
+ [['method'], 'in', 'range' => [self::METHOD_RULE, self::METHOD_SIMILARITY]],
+ [['status'], 'in', 'range' => [self::STATUS_PENDING, self::STATUS_APPROVED, self::STATUS_REJECTED]],
+ [['created_at', 'updated_at'], 'safe'],
+ [['category', 'subcategory', 'species', 'sort', 'type', 'color', 'approved_by', 'updated_at', 'size'], 'default', 'value' => null],
+ ];
+ }
+
+ public function isPending(): bool
+ {
+ return $this->status === self::STATUS_PENDING;
+ }
+
+ public function isApproved(): bool
+ {
+ return $this->status === self::STATUS_APPROVED;
+ }
+
+ public function getProduct(): ActiveQuery
+ {
+ return $this->hasOne(Products1c::class, ['id' => 'product_id']);
+ }
+}
--- /dev/null
+<?php
+
+declare(strict_types=1);
+
+namespace yii_app\services\automark;
+
+final class ParseResult
+{
+ public function __construct(
+ public readonly ?string $category,
+ public readonly ?string $subcategory,
+ public readonly ?string $species,
+ public readonly ?string $sort,
+ public readonly ?string $type,
+ public readonly ?int $size,
+ public readonly ?string $color,
+ public readonly float $confidence,
+ public readonly string $method,
+ ) {}
+
+ public function isConfident(float $threshold = 0.7): bool
+ {
+ return $this->confidence >= $threshold;
+ }
+
+ public function toArray(): array
+ {
+ return [
+ 'category' => $this->category,
+ 'subcategory' => $this->subcategory,
+ 'species' => $this->species,
+ 'sort' => $this->sort,
+ 'type' => $this->type,
+ 'size' => $this->size,
+ 'color' => $this->color,
+ 'confidence' => $this->confidence,
+ 'method' => $this->method,
+ ];
+ }
+}
--- /dev/null
+<?php
+
+declare(strict_types=1);
+
+namespace tests\unit\records;
+
+use Codeception\Test\Unit;
+use yii_app\records\Products1cAutomarkPrediction;
+
+/**
+ * @covers \yii_app\records\Products1cAutomarkPrediction
+ */
+class Products1cAutomarkPredictionTest extends Unit
+{
+ public function testTableName(): void
+ {
+ $this->assertSame('products_1c_automark_predictions', Products1cAutomarkPrediction::tableName());
+ }
+
+ public function testStatusConstants(): void
+ {
+ $this->assertSame(0, Products1cAutomarkPrediction::STATUS_PENDING);
+ $this->assertSame(1, Products1cAutomarkPrediction::STATUS_APPROVED);
+ $this->assertSame(2, Products1cAutomarkPrediction::STATUS_REJECTED);
+ }
+
+ public function testMethodConstants(): void
+ {
+ $this->assertSame('rule', Products1cAutomarkPrediction::METHOD_RULE);
+ $this->assertSame('similarity', Products1cAutomarkPrediction::METHOD_SIMILARITY);
+ }
+
+ public function testIsPendingMethod(): void
+ {
+ $model = new Products1cAutomarkPrediction();
+ $model->status = Products1cAutomarkPrediction::STATUS_PENDING;
+ $this->assertTrue($model->isPending());
+ }
+
+ public function testIsApprovedMethod(): void
+ {
+ $model = new Products1cAutomarkPrediction();
+ $model->status = Products1cAutomarkPrediction::STATUS_APPROVED;
+ $this->assertTrue($model->isApproved());
+ }
+}