@@ -5,7 +5,6 @@ package com.branddev.api.models.brand
55import com.branddev.api.core.Enum
66import com.branddev.api.core.JsonField
77import com.branddev.api.core.Params
8- import com.branddev.api.core.checkRequired
98import com.branddev.api.core.http.Headers
109import com.branddev.api.core.http.QueryParams
1110import com.branddev.api.errors.BrandDevInvalidDataException
@@ -16,22 +15,30 @@ import kotlin.jvm.optionals.getOrNull
1615
1716/* *
1817 * Automatically extract comprehensive design system information from a brand's website including
19- * colors, typography, spacing, shadows, and UI components.
18+ * colors, typography, spacing, shadows, and UI components. Either 'domain' or 'directUrl' must be
19+ * provided as a query parameter, but not both.
2020 */
2121class BrandStyleguideParams
2222private constructor (
23- private val domain: String ,
23+ private val directUrl: String? ,
24+ private val domain: String? ,
2425 private val prioritize: Prioritize ? ,
2526 private val timeoutMs: Long? ,
2627 private val additionalHeaders: Headers ,
2728 private val additionalQueryParams: QueryParams ,
2829) : Params {
2930
31+ /* *
32+ * A specific URL to fetch the styleguide from directly, bypassing domain resolution (e.g.,
33+ * 'https://example.com/design-system').
34+ */
35+ fun directUrl (): Optional <String > = Optional .ofNullable(directUrl)
36+
3037 /* *
3138 * Domain name to extract styleguide from (e.g., 'example.com', 'google.com'). The domain will
3239 * be automatically normalized and validated.
3340 */
34- fun domain (): String = domain
41+ fun domain (): Optional < String > = Optional .ofNullable( domain)
3542
3643 /* *
3744 * Optional parameter to prioritize screenshot capture for styleguide extraction. If 'speed',
@@ -57,20 +64,16 @@ private constructor(
5764
5865 companion object {
5966
60- /* *
61- * Returns a mutable builder for constructing an instance of [BrandStyleguideParams].
62- *
63- * The following fields are required:
64- * ```java
65- * .domain()
66- * ```
67- */
67+ @JvmStatic fun none (): BrandStyleguideParams = builder().build()
68+
69+ /* * Returns a mutable builder for constructing an instance of [BrandStyleguideParams]. */
6870 @JvmStatic fun builder () = Builder ()
6971 }
7072
7173 /* * A builder for [BrandStyleguideParams]. */
7274 class Builder internal constructor() {
7375
76+ private var directUrl: String? = null
7477 private var domain: String? = null
7578 private var prioritize: Prioritize ? = null
7679 private var timeoutMs: Long? = null
@@ -79,18 +82,31 @@ private constructor(
7982
8083 @JvmSynthetic
8184 internal fun from (brandStyleguideParams : BrandStyleguideParams ) = apply {
85+ directUrl = brandStyleguideParams.directUrl
8286 domain = brandStyleguideParams.domain
8387 prioritize = brandStyleguideParams.prioritize
8488 timeoutMs = brandStyleguideParams.timeoutMs
8589 additionalHeaders = brandStyleguideParams.additionalHeaders.toBuilder()
8690 additionalQueryParams = brandStyleguideParams.additionalQueryParams.toBuilder()
8791 }
8892
93+ /* *
94+ * A specific URL to fetch the styleguide from directly, bypassing domain resolution (e.g.,
95+ * 'https://example.com/design-system').
96+ */
97+ fun directUrl (directUrl : String? ) = apply { this .directUrl = directUrl }
98+
99+ /* * Alias for calling [Builder.directUrl] with `directUrl.orElse(null)`. */
100+ fun directUrl (directUrl : Optional <String >) = directUrl(directUrl.getOrNull())
101+
89102 /* *
90103 * Domain name to extract styleguide from (e.g., 'example.com', 'google.com'). The domain
91104 * will be automatically normalized and validated.
92105 */
93- fun domain (domain : String ) = apply { this .domain = domain }
106+ fun domain (domain : String? ) = apply { this .domain = domain }
107+
108+ /* * Alias for calling [Builder.domain] with `domain.orElse(null)`. */
109+ fun domain (domain : Optional <String >) = domain(domain.getOrNull())
94110
95111 /* *
96112 * Optional parameter to prioritize screenshot capture for styleguide extraction. If
@@ -221,17 +237,11 @@ private constructor(
221237 * Returns an immutable instance of [BrandStyleguideParams].
222238 *
223239 * Further updates to this [Builder] will not mutate the returned instance.
224- *
225- * The following fields are required:
226- * ```java
227- * .domain()
228- * ```
229- *
230- * @throws IllegalStateException if any required field is unset.
231240 */
232241 fun build (): BrandStyleguideParams =
233242 BrandStyleguideParams (
234- checkRequired(" domain" , domain),
243+ directUrl,
244+ domain,
235245 prioritize,
236246 timeoutMs,
237247 additionalHeaders.build(),
@@ -244,7 +254,8 @@ private constructor(
244254 override fun _queryParams (): QueryParams =
245255 QueryParams .builder()
246256 .apply {
247- put(" domain" , domain)
257+ directUrl?.let { put(" directUrl" , it) }
258+ domain?.let { put(" domain" , it) }
248259 prioritize?.let { put(" prioritize" , it.toString()) }
249260 timeoutMs?.let { put(" timeoutMS" , it.toString()) }
250261 putAll(additionalQueryParams)
@@ -391,6 +402,7 @@ private constructor(
391402 }
392403
393404 return other is BrandStyleguideParams &&
405+ directUrl == other.directUrl &&
394406 domain == other.domain &&
395407 prioritize == other.prioritize &&
396408 timeoutMs == other.timeoutMs &&
@@ -399,8 +411,15 @@ private constructor(
399411 }
400412
401413 override fun hashCode (): Int =
402- Objects .hash(domain, prioritize, timeoutMs, additionalHeaders, additionalQueryParams)
414+ Objects .hash(
415+ directUrl,
416+ domain,
417+ prioritize,
418+ timeoutMs,
419+ additionalHeaders,
420+ additionalQueryParams,
421+ )
403422
404423 override fun toString () =
405- " BrandStyleguideParams{domain=$domain , prioritize=$prioritize , timeoutMs=$timeoutMs , additionalHeaders=$additionalHeaders , additionalQueryParams=$additionalQueryParams }"
424+ " BrandStyleguideParams{directUrl= $directUrl , domain=$domain , prioritize=$prioritize , timeoutMs=$timeoutMs , additionalHeaders=$additionalHeaders , additionalQueryParams=$additionalQueryParams }"
406425}
0 commit comments