File size: 1,811 Bytes
343eed9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class ImageModel {
  private static readonly SUPPORTED_MODELS = ['flux', 'ssd-1b', 'sdxl', 'api', 'local'];

  private constructor(private readonly _value: string) {}

  static create(value: string): ImageModel {
    if (!this.SUPPORTED_MODELS.includes(value.toLowerCase())) {
      throw new Error(`Model not supported: ${value}`);
    }
    return new ImageModel(value.toLowerCase());
  }

  get value(): string {
    return this._value;
  }
}

class AspectRatio {
  private constructor(private readonly _value: string) {}

  static create(value: string): AspectRatio {
    const ratioRegex = /^\d+:\d+$/;
    if (!ratioRegex.test(value)) {
      throw new Error('Invalid Aspect Ratio format (expected W:H)');
    }
    return new AspectRatio(value);
  }

  get value(): string {
    return this._value;
  }
}

class VisualStyle {
  private constructor(private readonly _value: string) {}

  static create(value: string): VisualStyle {
    if (!value || value.trim().length === 0) {
      throw new Error('Visual style cannot be empty');
    }
    return new VisualStyle(value.trim().toLowerCase());
  }

  get value(): string {
    return this._value;
  }
}

export interface VisualConfigProps {
  model: string;
  aspectRatio: string;
  style: string;
}

export class VisualConfig {
  private constructor(
    public readonly model: ImageModel,
    public readonly aspectRatio: AspectRatio,
    public readonly style: VisualStyle
  ) {}

  static create(props: VisualConfigProps): VisualConfig {
    return new VisualConfig(
      ImageModel.create(props.model),
      AspectRatio.create(props.aspectRatio),
      VisualStyle.create(props.style)
    );
  }

  static createDefault(): VisualConfig {
    return this.create({
      model: 'flux',
      aspectRatio: '9:16',
      style: 'anime'
    });
  }
}